#include "GSDefeat.h"
#include "GSRankChange.h"

GSDefeat::GSDefeat()
{
	SetStateName("GSDEFEAT");
}

GSDefeat::~GSDefeat()
{
	DEVICE->GetDriver()->removeTexture(sprBG);
}

void GSDefeat::OnEnter()
{
	sprBG = Game::GetDevice()->GetDriver()->getTexture("data/sprites/bg/sprDefeat.png");
	fontCustomBig = Game::GetDevice()->GetInstance()->getGUIEnvironment()->getFont("data/strings/Showcard_Gothic.png");
	fontCustom = Game::GetDevice()->GetInstance()->getGUIEnvironment()->getFont("data/strings/fontcourier.bmp");
	fontCustomBig2 = Game::GetDevice()->GetInstance()->getGUIEnvironment()->getFont("data/strings/bigfont.png");
	fontCustom2 = Game::GetDevice()->GetInstance()->getGUIEnvironment()->getFont("data/strings/mv_boli.png");
	bgBox = core::rect<s32>(0,0,SCREEN_WIDTH, SCREEN_HEIGHT);
	deltaTime = NULL;
	isShowEnterText = true;
}

void GSDefeat::OnExit()
{

}

void GSDefeat::Update()
{
	gameTime = DEVICE->GetInstance()->getTimer()->getTime();
	if(deltaTime == NULL)
	{
		deltaTime = gameTime;
	}
	if(gameTime - deltaTime >= 1000)
	{
		isShowEnterText = !isShowEnterText;
		deltaTime = NULL;
	}
	if(DEVICE->receiver.IsKeyUp(KEY_RETURN))
	{
		if(PLAYER->isPlayerRankChange() == RCHANGE_DOWN)
			Game::PushState((GameState*)new GSRankChange(false));
		else if(PLAYER->isPlayerRankChange() == RCHANGE_NONE || PLAYER->m_isDoneRankChange)
			Game::PopState();
	}
}

void GSDefeat::Render()
{
	Game::GetDevice()->GetDriver()->beginScene(true, true, video::SColor(255,255,255,255));

	Game::GetDevice()->GetDriver()->draw2DImage(sprBG, core::position2di(0, 0), bgBox, 0, video::SColor(255,255,255,255), true);
	if(isShowEnterText)
		fontCustom2->draw("Enter to Continue", core::rect<s32>(SCREEN_WIDTH/2 - 100, 330,100,10), video::SColor(255,255,0,0));
	Game::GetDevice()->GetDriver()->endScene();
}